<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="referrer" content="never">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="../css/login.css">
  <style>
    .msg {
      display: flex;
      flex-direction: column;
      text-align: center;
    }
    .but{
      display: flex;
    }
  </style>
</head>

<body>
  <!-- 头部 -->
  <header>
    <div>
      <img src="	https://s10.mogucdn.com/mlcdn/c45406/190102_088f4i166l4gkl08k297h5kk8690i_260x200.png" alt="">
      <span>依《网络安全法》相关要求，即日起蘑菇街会员登陆需绑定手机。为保障您的账户安全及正常使用，如您尚未绑定，请尽快完成绑定，感谢您的理解和支持!</span>
    </div>

    <div>
      <div class="content">
        <div class="form-text">
          <form>
            <div class="form-group">
              <label for="username" class="col-sm-2 control-label">用户名</label>
              <div class="col-sm-10">
                <input type="text" name="name" class="form-control" id="username" placeholder="用户名">
              </div>
            </div>
            <div class="form-group">
              <label for="password" class="col-sm-2 control-label">密码</label>
              <div class="col-sm-10">
                <input type="password" name="pwd" class="form-control" id="password" placeholder="密码">
              </div>
            </div>
            <div class="but">
              <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                  <button type="submit" class="btn btn-default" name="dl">登录</button>
                </div>
              </div>
              <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                  <button type="submit" class="btn btn-default" name="zc">注册</button>
                </div>
              </div>
            </div>

          </form>

          <div name="msg" class="msg">
          </div>

        </div>

      </div>
    </div>

  </header>
</body>

<script src="../js/cookie.js"></script>
<script src="../tools/jquery.min.js"></script>
<script src="../js/ajax.js"></script>
<script>

  //点击注册 跳转
  $('[name="zc"]').click(function () {
    window.location.href='./reg.html'
    return false;
  });




  $('[name="dl"]').click(function () {
    setLogin();
    return false;
  });
  async function setLogin() {
    //获取数据
    let name = $('[name="name"]').val();
    let pwd = $('[name="pwd"]').val();
    //发送请求
    let res = await myPromiseAjax('../server/goods_login.php', 'post', { userName: name, userPwd: pwd }, 'json');
    console.log(res);


    //如果登录成功 设置cookie值
    if (res.result === 1) {
      mySetCookie('login', '1', 7 * 60 * 60 * 24, '/');

      $('[name="msg"]').html(`<span>还有3秒，跳转上一个页面</span><a href="./index.html">点击跳转首页</a>`);
      let num = 3;
      let time = setInterval(function () {
        num--;
        $('[name="msg"]').html(`<span>还有${num}秒，跳转上一个页面</span><a href="./index.html">点击跳转首页</a>`);

        if (num === 1) {

          window.location.href = window.location.search.substr(1);
          clearInterval(time);
        }

      }, 1000);
    } else {
      window.alert("您的用户或密码不正确！");
    }

  }




</script>

</html>